package com.hfdg.authority.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfdg.prototype.base.utils.TimeUtils;
import com.hfdg.authority.mapper.AuthUserRoleMapper;
import com.hfdg.authority.entity.AuthUserRole;
import com.hfdg.authority.service.AuthUserRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @ClassName AuthUserRoleServiceImpl
 * @Description TODO
 * @Author yuelh
 * @Date 2019/1/19 18:26
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
@Service
public class AuthUserRoleServiceImpl implements AuthUserRoleService {
    @Autowired
    AuthUserRoleMapper authUserRoleMapper;

    @Override
    public String insert(AuthUserRole authUserRole) {
        String uid = UUID.randomUUID().toString();
        authUserRole.setUid(uid);
        authUserRole.setDelFlag("0");
        authUserRole.setCreateTime(new Date());
        authUserRoleMapper.insert(authUserRole);
        return uid;
    }

    @Override
    public Integer update(AuthUserRole authUserRole) {
        authUserRole.setUpdateTime(new Date());
        return authUserRoleMapper.update(authUserRole);
    }

    @Override
    public Integer  delete(String uid) {
        return authUserRoleMapper.delete(uid);
    }
    @Override
    public Integer batchDelete(String[] uids) {
            return authUserRoleMapper.batchDelete(uids);
    }

    @Override
    public AuthUserRole get(String uid) {
        return authUserRoleMapper.get(uid);
    }

    @Override
    public List<AuthUserRole> list(AuthUserRole authUserRole) {
    return  authUserRoleMapper.list(authUserRole);
    }

    @Override
    public PageInfo<AuthUserRole> getPagingData(int offset, int limit,String orderBy, AuthUserRole authUserRole) {
        if(null==orderBy|| StringUtils.isBlank(orderBy)){
        PageHelper.startPage((offset/limit)+1,limit);
        }else{
        PageHelper.startPage((offset/limit)+1,limit,orderBy);
        }
        PageInfo<AuthUserRole> pageInfo =new PageInfo<>(authUserRoleMapper.list(authUserRole));
            return pageInfo;
            }
    @Override
    public String insertOrUpdate(AuthUserRole authUserRole){
        if(null!=authUserRole.getUid()){
            this.update(authUserRole);
        }else{
            this.insert(authUserRole);
        }
        return authUserRole.getUid();
    }
            }
